class ReposCommits
  attr_accessor :github

  def initialize(github)
    @github = github
  end

  def listCommits(repo, sha=nil, path=nil, user=nil)
    username = user == nil ? @github.username : user
    params = {
        :sha => sha,
        :path => path
    }
    params = @github.removeEmptyParams(params)
    params = @github.parameterize(params)
    url = params ? 'repos/%s/%s/commits?%s' % [username, repo, params] : 'repos/%s/%s/commits'
    @github.get(url)
  end

  def getCommit(repo, sha, user=nil)
    username = user == nil ? @github.username : user
    @github.get('repos/%s/%s/commits/%s' % [username, repo, sha])
  end

  def listRepoComments(repo, user=nil)
    username = user == nil ? @github.username : user
    @github.get('repos/%s/%s/comments' % [username, repo])
  end

  def listComments(repo, sha, user=nil)
    username = user == nil ? @github.username : user
    @github.get('repos/%s/%s/comments/%s/comments' % [username, repo, sha])
  end

  def createComment(repo, sha, body, line, path, position, user=nil)
    username = user == nil ? @github.username : user
    params = {
        :body => body,
        :commit_id => sha,
        :line => line,
        :path => path,
        :position => position
    }
    data = params.to_json
    @github.post('repos/%s/%s/commits/%s/comments' % [username, repo, sha], data)
  end

  def getSingleComment(repo, id, user=nil)
    username = user == nil ? @github.username : user
    @github.get('repos/%s/%s/comment/%s' % [username, repo, id])
  end

  def updateComment(repo, id, body, user=nil)
    username = user == nil ? @github.username : user
    params = {
        :body => body
    }
    data = params.to_json
    @github.post('repos/%s/%s/comments/%s' % [username, repo, id], data)
  end

  def CompareCommits(repo, base, head, user=nil)
    username = user == nil ? @github.username : user
    @github.get('repos/%s/%s/compare/%s...:%s' % [username, repo, base, head])
  end


  def deleteComment(repo, id, user=nil)
    username = user == nil ? @github.username : user
    @github.delete('repos/%s/%s/comments/%s' % [username, repo, id])
  end
end